<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气案例-监视属性-深度监视</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>今天天气 {{info}}</h1>
        <button @click="changeWeather">切换天气</button>
        <hr>    
        <h2>a的值时:{{numbers.a}}</h2>
        <button @click="numbers.a++">点击a++</button>
    </div> 


    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: '#root',
            data:{ 
                isHot: true,
                numbers:{
                    a:1,
                    b:1
                }
            },
            computed: {
                info(){
                    return this.isHot ? '热' : '爽'
                }
            },
            methods: {
                changeWeather(){
                    this.isHot = !this.isHot
                }
            },
            watch:{
                isHot :{
                    handler(newValue, oldValue){
                        console.log('isHot改变了w1', newValue, oldValue)
                    }
                },
                /* // 多级结构中某个属性变化
                'numbers.a':{
                    handler(newValue, oldValue){
                        console.log('a', newValue, oldValue)
                    }
                }, */
                // 多级结构中所有属性变化  
                numbers:{
                    deep:true, // 默认 false
                    handler(newValue, oldValue){
                        console.log('a', newValue, oldValue)
                    }
               }
            }
        })
    </script>

</body>
</html>